package com.nondo.test;

import java.io.IOException;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import com.aliyuncs.http.FormatType;
import com.aliyuncs.http.HttpRequest;
import com.aliyuncs.http.HttpResponse;
import com.aliyuncs.http.MethodType;
import com.nondo.rdp.FinanceApplication;
import com.nondo.rdp.auth.service.UserMessageService;

@RunWith(SpringRunner.class)
@SpringBootTest(classes=FinanceApplication.class)
public class MessageDemo {
	@Autowired
	private UserMessageService userMessageService;
	
	private static final String domain = "http://10.10.0.136:10086";
	
	private static final String token = "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsInNjb3BlcyI6WyJST0xFX2FkbWluaXN0cmF0b3IiXSwiWC1TZWNyZXQiOiJaR1kzTlRRME9UZ3RZMlptWlMwMFlqRXpMVGsyTXpndE16SmxOVFExWVdFM1pEZGoiLCJYLWFsZ29yaXRobSI6IkhtYWNTSEE1MTIiLCJpc3MiOiJodHRwOi8vd3d3Lmppbmx1b2JvLmNvbSIsImlhdCI6MTUwOTM1ODgyOSwiZXhwIjoxNTA5NDQ1MjI5fQ.ChjteLMNYVp3gRO028294tCOXZ1PLmjECdhiKNb5NKkYcXIVpeeqFu3rgQhSk-YNt9k4Ccha1A506G4ORBESnw";
	
	
	@Test
	public void restAddMessage() {
		String requestBody = "{\"title\": \"消息添加测试\",\"content\": \"新增了一条带链接参数的消息\",\"method\":\"message\",\"extra\":\"%7b%22url%22%3a%22http%3a%2f%2f10.10.0.136%3a10086%2fapi%2fapp%2fmessage%2finfo%2f1%22%7d\"}";
		HttpRequest request = new HttpRequest(domain + "/api/admin/message/add");
		request.putHeaderParameter("X-Authentication", token);
		request.setContent(requestBody.getBytes(), "UTF-8", FormatType.JSON);
		request.setMethod(MethodType.POST);
		try {
			HttpResponse httpResponse = HttpResponse.getResponse(request);
			System.out.println(httpResponse.getContent().toString());
		} catch (IOException e) {
			e.printStackTrace();
			Assert.fail(e.getMessage());
		}
	}
}